// generated, but should be first
#include "example/echo.gen.h"

#include <iostream>
#include <fstream>
#include <string>
#include "example/echo.pb.h"
#include "pgi.h"

// generated
#include "example/dispatch.gen.h"

using namespace std;


namespace tutorial {

typedef struct EchoApp_s {
  int i;
} EchoApp;


// TODO: Look up the person?
bool IndexHandler(EchoApp* app_ctx,
                 const IndexRequest& request, IndexResponse* response) {
  response->set_id(request.id() + app_ctx->i);
  response->set_name("THIS IS MY NAME");
  return true;
}

// TODO: Look up the person?
bool EchoHandler(EchoApp* app_ctx,
                 const EchoRequest& request, EchoResponse* response) {

  // Hm is there a better way to do this?  It would be nicer to return body_data
  // directly.  Could have some way of specifying this in the route?   If it has
  // a template?
  // 
  // What about message, and so forth though?

  response->mutable_body_data()->set_id(request.id() + app_ctx->i);
  return true;
}


};

// Main function:  Reads the entire address book from a file,
//   adds one person based on user input, then writes it back out to the same
//   file.
int main(int argc, char* argv[]) {
  // Verify that the version of the library that we linked against is
  // compatible with the version of the headers we compiled against.
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  tutorial::EchoApp app_ctx;
  if (!pgi_serve(&tutorial::echo_dispatch, (void*)&app_ctx)) {
    return 1;
  }

  // Optional:  Delete all global objects allocated by libprotobuf.
  google::protobuf::ShutdownProtobufLibrary();

  return 0;
}
